package com.das.mechanic_base.adapter.alone;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.bean.alone.UnCompleteBean;
import com.kproduce.roundcorners.RoundTextView;

import java.util.ArrayList;
import java.util.List;

public class X3UnCompleteAdapter extends RecyclerView.Adapter<X3UnCompleteAdapter.X3UnCompleteHolder> {

    private List<UnCompleteBean> mList;

    private Context mContext;

    public X3UnCompleteAdapter(Context mContext) {
        this.mContext = mContext;
        this.mList = new ArrayList<>();
    }

    public void changeUnComplete(List<UnCompleteBean> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public X3UnCompleteHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new X3UnCompleteHolder(LayoutInflater.from(mContext).inflate(R.layout.x3_uncomplete_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull X3UnCompleteHolder holder, int position) {

        holder.tv_title.setText(mList.get(position).description + "");

        holder.rv_check.setOnClickListener(v -> {
            if (iOnClickToAlone != null) {
                iOnClickToAlone.iOnClickToAlone(mList.get(position));
            }
        });
    }

    IOnClickToAlone iOnClickToAlone;

    public X3UnCompleteAdapter setiOnClickToAlone(IOnClickToAlone iOnClickToAlone) {
        this.iOnClickToAlone = iOnClickToAlone;
        return this;
    }

    public interface IOnClickToAlone {
        void iOnClickToAlone(UnCompleteBean unCompleteBean);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class X3UnCompleteHolder extends RecyclerView.ViewHolder {
        TextView tv_title;
        RoundTextView rv_check;
        public X3UnCompleteHolder(@NonNull View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.tv_title);
            rv_check = itemView.findViewById(R.id.rv_check);
        }
    }
}
